
import cTitle from "components/title";
export default {
  components: {
    cTitle
  },
  data() {
    return {
      tabInd:0,
      time:-1,
      selecttime:false,
      uid:"",
      team_count:"0",//团队人数
      order_count:"0",//总单量
      team_performance:"0",//总业绩
      direct_count:"0",//总粉丝人数
      direct_list:[],//总粉丝
      month:"",
      uid:"",
      minDate: new Date(2000,1,1),
      maxDate: new Date(),
      currentDate: new Date(),
      rewardList:[],
      total:0,
      page:1,
      isLoding:false
    };
  },

  mounted() {
    window.addEventListener('scroll', this.handleScroll);
   },
   destroyed() {
    window.removeEventListener('scroll', this.handleScroll);
  },

  created() {
    this.uid = localStorage.getItem("uid")
    this.tabInd = 0
    // 团队信息
    $http.post("Baoxian.getTeamInfo", {
      uid:this.uid
    }).then(res=>{
      if(res.result== 1){
        this.team_count = res.data.team_count
        this.order_count = res.data.order_count
        this.team_performance = res.data.team_performance
      }
      // console.log(res);
    })
    this.getDirectTeam()
   
  },

  methods: {
    selectTab(e){
      if(this.tabInd == e)return
      this.tabInd = e
      if(e == 1){
        this.onConfirm(1)
      }else{
        this.getDirectTeam()
      }
    },
    selectDay(e){
      this.time = e
    },
    selectdayshow(e){
      this.selecttime = !this.selecttime
    },
    // 获取服务费
    getFuwu(){
      this.isLoding = true
      $http.post("Baoxian.rewardList", {
        uid:this.uid,
        month:this.month,
        page:this.page,
      }).then(res=>{
        if(res.result== 1){
          let arr = res.data.data
          this.rewardList = [...this.rewardList,...arr]
          this.total = res.data.total
          this.isLoding = false
          if(this.rewardList.length >= this.total){
            this.isLoding = true
          }
        }
      })
    },
    // 直推用户
    getDirectTeam(){
      $http.post("Baoxian.getDirectTeam", {
        uid:this.uid
      }).then(res=>{
        if(res.result== 1){
          this.direct_count = res.data.direct_count
          this.direct_list = res.data.direct_list
        }
      })
    },
    formatter(type, val) {
      if (type === 'year') {
        return `${val}年`;
      } else if (type === 'month') {
        return `${val}月`;
      }
      return val;
    },
    onConfirm(e){
      let d = e == 1 ? new Date() : new Date(e)
      let y = d.getFullYear()
      let m = d.getMonth() + 1
      this.month = y + "-" + (m>9?m:('0'+m))
      this.rewardList = []
      this.page = 1
      this.isLoding = false
      this.getFuwu()
      this.selecttime = false
    },
    handleScroll() {
      const { scrollTop, scrollHeight, clientHeight } = document.documentElement;
      // 判断是否滚动到底部
      if (scrollTop + clientHeight >= scrollHeight - 25 && this.tabInd == 1) {
        if(!this.isLoding && this.rewardList.length < this.total){
          this.page++
          this.getFuwu()
        }else{
          this.isLoding = true
        }
        // 这里可以添加你需要执行的逻辑，比如加载更多数据
      }
    },

  }
};